﻿$(document).ready(function () {
    $("#table").jqGrid({
        datatype: 'json',
        url: '/NaturezasOperacao/List',
        mtype: 'GET',
        colNames: ['', 'Id', 'CFOP', 'Descrição', 'Ativo'],
        colModel: [
            { name: "actions", formatter: "actions", editable: false, sortable: false, resizable: false, search: false, align: 'center', width: 28, "formatoptions": { keys: false, editbutton: false, delbutton: true} },
            { name: 'ID_NTOP', index: 'ID_NTOP', width: 100, sortable: false, align: 'right', search: false, hidden: true },
            { name: 'CFOP_NTOP', index: 'CFOP_NTOP', width: 80, editable: true, align: 'right', searchoptions: { sopt: ['eq']} },
            { name: 'DESC_NTOP', index: 'DESC_NTOP', width: 600, editable: true, searchoptions: { sopt: ['cn', 'eq']} },
            { name: 'ATIVO_NTOP', index: 'ATIVO_NTOP', width: 60, align: 'center', editable: true, search: false, edittype: 'checkbox', editoptions: { value: "Sim:Não"} }
        ],
        gridComplete: function () { loadInputs(); },
        pager: '#pager',
        height: 'auto',
        rowNum: 15,
        rowList: [10, 20, 30, 50],
        sortname: 'ID_NTOP',
        sortorder: "asc",
        editurl: '/NaturezasOperacao/Delete',
        ondblClickRow: function (id) {
            editRow('table', '/NaturezasOperacao/Update', id);
        }
    }).navGrid("#pager", {
        edit: false, add: false, del: false, search: true, refresh: true
    }).navButtonAdd("#pager", {
        caption: '',
        buttonicon: 'ui-icon-circle-plus',
        onClickButton: function () {
            $("#table").addRowData(0, {
                ID_NTOP: '', CFOP_NTOP: '', DESC_NTOP: '', ATIVO_NTOP: 'Sim'
            }, 'first');
            addRow('table', '/NaturezasOperacao/Update ');
        },
        title: "adicionar natureza de operação",
        position: "last"
    });
});